#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string countAndSay(int n) {
        string s = "1";
        for (int i = 1; i < n; i++) {
            string tmp;
            for (int left = 0, right = 0; right < s.size();) {
                while (s[left] == s[right]) {
                    right++;
                }
                tmp += to_string(right - left) + s[left];
                left = right;
            }
            s = tmp;
        }
        return s;
    }
};